<template>
	<el-dialog :visible.sync="addVisible" width="80%" :show-close='false' :closeOnClickModal='false' class="addSampleForm standardseries dataEntrySeries"
	 ref="standardseries" append-to-body>
		<span slot="title" class="dialog-title">
				标准系列
				<!--<el-button type="primary" @click="historyLine" size="mini" class="popupClose" style="margin-right:70px;" v-if = "standarModel == 'mygrouptest'">历史曲线</el-button>-->
				<el-button @click="closeStandardSeriesShow" size="mini" class="popupClose">关闭</el-button>
			</span>
		<div class="standardTitle">
			<el-input placeholder="请输入内容" size="mini" v-model="name" :disabled="standarModel != 'mygrouptest'"></el-input>标准系列配置记录表
		</div>
		<div class="form">
			<el-form label-width="80px" :inline="false" class="demo-form-inline" :model="standardSeriesForm" :rules="standardSeriesFormRules"
			 ref="standardSeriesForm">

				<el-form-item label="编号" prop="code">
					<el-col :span="22">
						<el-input placeholder="请输入内容" size="mini" v-model="standardSeriesForm.code" :disabled="standarModel != 'mygrouptest'"></el-input>
					</el-col>
				</el-form-item>
				<el-form-item label="温度(℃)" prop="temperature">
					<el-col :span="22">
						<el-input size="mini" v-model="standardSeriesForm.temperature" :min="0" class="controlsPosition" style="width:100%"
						 :disabled="standarModel != 'mygrouptest'"></el-input>

					</el-col>
				</el-form-item>
				<el-form-item label="湿度(%)" prop="humcodeity">
					<el-col :span="22">
						<el-input size="mini" v-model="standardSeriesForm.humcodeity" :min="0" class="controlsPosition" style="width:100%"
						 :disabled="standarModel != 'mygrouptest'"></el-input>
					</el-col>
				</el-form-item>
				<el-form-item label="是否应用" prop="doUse">
					<el-col :span="22">
						<el-checkbox v-model="standardSeriesForm.doUse" @change="itemSize" :disabled="standarModel != 'mygrouptest'"></el-checkbox>
					</el-col>
				</el-form-item>
				<el-form-item label="配置日期" prop="configDate">
					<el-col :span="22">
						<el-date-picker size="mini" type="date" v-model="standardSeriesForm.configDate" style="width:100%" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
						 placeholder="选择日期" :disabled="standarModel != 'mygrouptest'">
						</el-date-picker>
					</el-col>
				</el-form-item>
				<el-form-item label="配置人" prop="configMan">
					<el-col :span="22">
						<el-select v-model="standardSeriesForm.configMan" placeholder="请选择" size="mini" :disabled="standarModel != 'mygrouptest'">
							<el-option v-for="item in userData" :key="item.account" :label="item.name" :value="item.account" :disabled="item.disabled">
							</el-option>
						</el-select>
					</el-col>
				</el-form-item>
				<el-form-item label="校核人" prop="checker" v-if="false">
					<el-col :span="22">
						<el-select v-model="standardSeriesForm.checker" placeholder="请选择" size="mini" :disabled="standarModel != 'mygrouptest'">
							<el-option v-for="item in userData" :key="item.account" :label="item.name" :value="item.account" :disabled="item.disabled">
							</el-option>
						</el-select>

					</el-col>
				</el-form-item>
        <el-form-item label="扣除空白"  label-width="125px" prop="mustZone" style = "width:10%;">
            <el-col :span="22">
                <el-checkbox v-model="standardSeriesForm.mustZone" :disabled="standarModel != 'mygrouptest'"></el-checkbox>
            </el-col>
        </el-form-item>

			</el-form>

		</div>
		<div class="elTab standardTable">
			<el-tabs style="width:100%;" v-model="activeName">
				<el-tab-pane label="标准溶液" name="first">
					<el-button size="mini" type="primary" style="float:right" class="inlineBlock" @click="addStandardSolution" v-if="standarModel == 'mygrouptest'">添加标准溶液</el-button>
					<el-radio-group v-model="matterType" class="checkbox inlineBlock" style="float:right;margin-right:55px;" :disabled="standarModel != 'mygrouptest'">
						<el-radio :label="1">单标</el-radio>
						<el-radio :label="2">混标</el-radio>
					</el-radio-group>
					<el-table :data="standardSolution" style="width: 100%" size="mini" class="solution">
						<el-table-column property="name" label="标准溶液类型" fixed min-width="150">
							<template slot-scope="scope">
								<el-input type="text" size="mini" v-model="scope.row.name" placeholder="请输入内容" :disabled="standarModel != 'mygrouptest'"></el-input>
							</template>
						</el-table-column>
						<el-table-column property="matter" label="标准物质名称及编号" min-width="150">
							<template slot-scope="scope">
								<el-input type="text" size="mini" v-model="scope.row.matter" placeholder="请输入内容" :disabled="standarModel != 'mygrouptest'"></el-input>
							</template>
						</el-table-column>
						<el-table-column property="matterConcen" :render-header="renderHeader" min-width="150">
							<template slot-scope="scope">
								<el-input size="mini" v-model="scope.row.matterConcen" :min="0" class="controlsPosition" :disabled="standarModel != 'mygrouptest'"></el-input>

							</template>
						</el-table-column>
						<el-table-column property="matterAmount" min-width="150" :render-header="renderHeader">
							<template slot-scope="scope">
								<el-input size="mini" v-model="scope.row.matterAmount" :min="0" class="controlsPosition" :disabled="standarModel != 'mygrouptest'"></el-input>
							</template>
						</el-table-column>
						<el-table-column property="volum" :render-header="renderHeader" min-width="150">
							<template slot-scope="scope">
								<el-input size="mini" v-model="scope.row.volum" :min="0" class="controlsPosition" :disabled="standarModel != 'mygrouptest'"></el-input>

							</template>
						</el-table-column>
						<el-table-column property="matrix" label="基体" min-width="100">
							<template slot-scope="scope">
								<el-input type="text" size="mini" v-model="scope.row.matrix" placeholder="请输入内容" :disabled="standarModel != 'mygrouptest'"></el-input>
							</template>
						</el-table-column>

						<el-table-column property="configConcen" :render-header="renderHeader" min-width="150">
							<template slot-scope="scope">
								<el-input size="mini" v-model="scope.row.configConcen" :min="0" class="controlsPosition" :disabled="standarModel != 'mygrouptest'"></el-input>

							</template>
						</el-table-column>

						<el-table-column label="操作" min-width="100" v-if="standarModel == 'mygrouptest'">
							<template slot-scope="scope">
								<el-button type="text" size="small" @click="deleteStandardSolution(scope.$index)">删除</el-button>
							</template>
						</el-table-column>
					</el-table>
				</el-tab-pane>
				<el-tab-pane label="标准系列" name="second">
					<el-button size="mini" type="primary" style="float:right" class="inlineBlock" @click="addStandardSeries" v-if="standarModel == 'mygrouptest'">添加标准系列</el-button>
					<el-radio-group v-model="configWay" class="checkbox inlineBlock" style="float:right;margin-right:55px;" :disabled="standarModel != 'mygrouptest'">
						<el-radio :label="1">人工配置</el-radio>
						<el-radio :label="2">仪器配置</el-radio>
					</el-radio-group>
					<el-table :data="standardSeries" style="width: 100%" size="mini"  class="tableCon seriesTable">
						<el-table-column label="序号" width="50">
							<template slot-scope="scope">
								{{scope.$index+1}}
							</template>
						</el-table-column>
						<el-table-column property="seriesItem" label="项目" width="100">
							<template slot-scope="scope">
								<el-input type="text" size="mini" v-model="scope.row.seriesItem" placeholder="请输入内容" :disabled="standarModel != 'mygrouptest'"></el-input>
							</template>
						</el-table-column>
						<el-table-column label="标准系列" class="seriesTd" min-width="300px">
							<template slot-scope="scope">
								<el-table :data="scope.row.custom.standardSeriesChild" style="width: 100%" size="mini" class="seriesChildTable">
									<el-table-column label="标准系列序号" width="110px" property="title" fixed>
									</el-table-column>
									<el-table-column property="unitValue" width="110px" fixed>
										<template slot-scope="scope">
											<el-select v-model="scope.row.unitValue" size="mini" filterable placeholder="单位" class="unitSeries" :disabled="standarModel != 'mygrouptest'">
												<el-option v-for="item in allUnit" :key="item.id" :label="item.ename" :value="item.id" :disabled = "item.status == 0">
												</el-option>
											</el-select>
										</template>
									</el-table-column>
									<el-table-column v-for="col in scope.row.custom.colsData" :key="col.value" :label="col.label">
										<template slot-scope="scope">
											<el-input size="mini" v-model="scope.row[col.value]" :min="0" class="controlsPosition borderNone deal" :disabled="standarModel != 'mygrouptest'"></el-input>

										</template>
									</el-table-column>

								</el-table>
							</template>
						</el-table-column>
						<el-table-column label="操作" width="90" v-if="standarModel == 'mygrouptest'">
							<template slot-scope="scope">
								<el-button type="text" size="small" @click="copyStandardSeries(scope.row)" :disabled="standardSeriesForm.doUse">复制</el-button>
								<el-button type="text" size="small" @click="deleteStandardSeries(scope.$index)">删除</el-button>
							</template>
						</el-table-column>
					</el-table>
				</el-tab-pane>
				<el-tab-pane label="曲线图谱" name="third" v-if="standarModel != 'mygrouptest'">
					<div style="width: 100%; height: 100%;margin:auto;overflow:auto;">
						<el-table :data="standardTable.seriesRow" style="width: 100%;height:120px" size="mini">
							<el-table-column label="标准系列序号" width="110px" property="title" fixed>
							</el-table-column>

							<el-table-column v-for="col in standardTable.seriesTitle" :key="col.value" :label="col.label">
								<template slot-scope="scope">
									{{scope.row[col.value]}}
								</template>
							</el-table-column>
						</el-table>
						<!--getCoefficientObj-->
						<div style="height:350px;">
							<div style="width:18%;float:left;margin-top:10px;">
								<p style="height:40px;line-height:40px;">a ：{{getCoefficientObj.slope}}</p>
								<p style="height:40px;line-height:40px;">b ：{{getCoefficientObj.deviation}}</p>
								<p style="height:40px;line-height:40px;">R : {{getCoefficientObj.coefficent}}</p>

							</div>
							<div id="seriesMap" style="width:82%;height:300px;margin:auto;float:right"></div>
						</div>

					</div>
				</el-tab-pane>
				<el-tab-pane label="附件" :disabled="standardSeriesForm.doUse" name="fourth">
					<!-- <el-button type="primary" size="mini" style="float:right;margin-bottom:5px">上传</el-button> -->
					<el-table style="width: 100%" size="mini" :data="attachmentBeanList" height="calc(100% - 33px)">
					    <el-table-column label="序号" min-width="50px">
					        <template slot-scope="scope">
					            {{scope.$index+1}}
					        </template>
					    </el-table-column>
					    <el-table-column property="fileName" label="附件名称" min-width="200px" :show-overflow-tooltip="true">
					    </el-table-column>
					    <el-table-column property="fileSize" label="附件大小" min-width="100px">
					        <template slot-scope="scope">
					            {{scope.row.fileSize == 0 ? 1 : scope.row.fileSize }} KB
					        </template>
					    </el-table-column>
					    <el-table-column property="createByName" label="上传人" min-width="80px">
					    </el-table-column>
					    <el-table-column property="createTime" label="上传时间" min-width="100px" :formatter="timeFormatter">
					    </el-table-column>
					    <el-table-column label="操作" min-width="100px">
					        <template slot-scope="scope">
					            <!-- <el-button type="text" size="mini" @click="deleteattachment(scope.row)">删除</el-button> -->
					            <!--downloadattachment-->
					            <el-button type="text" size="mini" @click="downloadattachment(scope.row)">下载</el-button>
					        </template>
					    </el-table-column>
					</el-table>
				</el-tab-pane>
			</el-tabs>
		</div>
	</el-dialog>
</template>

<script>
	import $ from 'jquery'
	import { mapState } from 'vuex'


	export default {
		data() {
			return {
				isUse: false,
				name: '', //标准系列配置表头
				matterType: 1,
				configWay: 1,
				standardSolution: [], //标准溶液
				standardSeriesForm: {
					code: '',
					configDate: null,
					temperature: '',
					humcodeity: '',
					doUse: false,
          mustZone:true,
					checker: '',
					configMan: JSON.parse(sessionStorage.getItem('laboratoryAccountInfo')).loginid,

				},//标准系列表格
				standardSeriesFormRules: { //标准系列验证规则
					configDate: [
						{ required: true, type: 'string', message: '请选择配置时间', trigger: 'change' },
					],
					temperature: [
						{ required: true, type: 'number', message: '请填写温度', trigger: 'blur' },
					],
					humcodeity: [
						{ required: true, type: 'number', message: '请填写湿度', trigger: 'blur' }
					],
					configMan: [
						{ required: true, message: '请选择配置人', trigger: 'change' },
					],
					checker: [
						{ required: true, message: '请选择校核人', trigger: 'change' },
					],
				},
				unitTitle: {
					unitOne: '', //标准物质用量单位
					unitTwo: '', //标准物质浓度单位
					unitThree: '',//定容体积 单位
					unitFour: '', //配置浓度绑定单位
				},
				standardSeries: [], //标准系列
				criterionId: '', //更新时要传的id
				breakFlag: 1, //是否中断提交
				disabledUnit: true, //是否禁止填写单位
				testpanelForm: {},
				isDisabled: false, //是否可用
				activeName: 'first',
				standardTable: {}, //标准系列表
				getCoefficientObj: {
					coefficent: null, //相关系数
					deviation: null, //截距
					slope: null, //斜率
				},
				userData:[],
				allUnit:[],
        attachmentBeanList:[],

			}
		},
		watch: {
			addVisible(val) {
				if (val) {

					this.standardSeriesForm = this.standardSeriesDetail;
          if(this.standardSeriesForm.mustZone === "" || this.standardSeriesForm.mustZone === null
          || this.standardSeriesForm.mustZone === undefined){
            this.standardSeriesForm.mustZone = false;  //展示  如果没有值则为false
          }
					this.testpanelForm = this.testpanelDetail;
           console.log(this.standardSeriesForm)
						this.criterionId = this.standardSeriesForm.id //更新时保存的id
						this.name = this.standardSeriesForm.name;
						this.standardSolution = this.standardSeriesForm.solutionBeans; //标准溶液数据
						// 标准系列数据
						var temp = []
						for (var i in this.standardSeriesForm.itemBeans) {
							var obj = {};
							obj.seriesItem = this.standardSeriesForm.itemBeans[i].itemName; //项目名称
							obj.custom = {};
							obj.custom.standardSeriesChild = [] //子表数组
							obj.custom.colsData = []
							for (var j in this.standardSeriesForm.itemBeans[i].seriesBeans) { //子表标头 std1 std2 ...
								var colsDataObj = {};
								colsDataObj.label = this.standardSeriesForm.itemBeans[i].seriesBeans[j].seriesSort

								colsDataObj.value = this.standardSeriesForm.itemBeans[i].seriesBeans[j].seriesSort
								obj.custom.colsData.push(colsDataObj)
							}
							var arr = [];
							for (var k = 0; k < 4; k++) {	 //子表的四行数据
								var childObj = {};
								for (var j in this.standardSeriesForm.itemBeans[i].seriesBeans) { //遍历列（一共有几个std）
									if (k == 0) {
										childObj.title = '标准使用液浓度';
										childObj.unitValue = this.standardSeriesForm.itemBeans[i].unitOne;
										childObj[this.standardSeriesForm.itemBeans[i].seriesBeans[j].seriesSort] = this.standardSeriesForm.itemBeans[i].seriesBeans[j].criterionConcen;
									} else if (k == 1) {
										childObj.title = '标准物质用量';
										childObj.unitValue = this.standardSeriesForm.itemBeans[i].unitTwo;
										childObj[this.standardSeriesForm.itemBeans[i].seriesBeans[j].seriesSort] = this.standardSeriesForm.itemBeans[i].seriesBeans[j].matterAmount;
									} else if (k == 2) {
										childObj.title = '定容量';
										childObj.unitValue = this.standardSeriesForm.itemBeans[i].unitThree;
										childObj[this.standardSeriesForm.itemBeans[i].seriesBeans[j].seriesSort] = this.standardSeriesForm.itemBeans[i].seriesBeans[j].volum;
									} else if (k == 3) {
										childObj.title = '标准系列浓度';
										childObj.unitValue = this.standardSeriesForm.itemBeans[i].unitFour;
										childObj[this.standardSeriesForm.itemBeans[i].seriesBeans[j].seriesSort] = this.standardSeriesForm.itemBeans[i].seriesBeans[j].seriesConcen;
									}
								}

								obj.custom.standardSeriesChild.push(childObj)

							}
							temp.push(obj)
						}
						this.standardSeries = temp;
						this.matterType = this.standardSeriesForm.matterType; //单标或者混标
						this.configWay = this.standardSeriesForm.configWay; //人工配置或者仪器配置
						// 标准溶液表头四个单位
						this.unitTitle.unitOne = this.standardSeriesForm.unitOne;
						this.unitTitle.unitTwo = this.standardSeriesForm.unitTwo
						this.unitTitle.unitThree = this.standardSeriesForm.unitThree
						this.unitTitle.unitFour = this.standardSeriesForm.unitFour

					if (this.standarModel != 'mygrouptest') { //如果弹框是从数据录入点击弹出，输入框不可用
						this.isDisabled = true;
					}
				}
			},
			activeName(val) {
				if (val == "third") {
					console.log(this.standardSeriesForm.itemBeans[0].seriesBeans)
					this.standardTable.series = this.standardSeriesForm.itemBeans[0].seriesBeans
					this.standardTable.seriesRow = []; //表两列数据
					this.standardTable.seriesTitle = []; //表头数据
					if (this.standardTable.series != undefined) {
						for (var i in this.standardTable.series) {  //组装表头
							var obj = {};
							obj.value = this.standardTable.series[i].seriesSort;
							obj.label = this.standardTable.series[i].seriesSort;
							this.standardTable.seriesTitle.push(obj);
						}
					}
					//渲染曲线图谱的数据
					var seriesFlag = false;
					for (var k = 0; k < 2; k++) {//渲染标准系列表的内容
						var childObj = {};
						if (this.standardTable.series != undefined) {
							for (var i in this.standardTable.series) {
								if (k == 0) {
									childObj.title = '标准系列浓度';
									childObj[this.standardTable.series[i].seriesSort] = this.standardTable.series[i].seriesConcen;

								} else if (k == 1) {
									childObj.title = '标准系列信号值';
									childObj[this.standardTable.series[i].seriesSort] = this.standardTable.series[i].signal;
									// childObj[this.standardTable.series[i].seriesSort] = this.stringNotEmpty(this.signalObj[this.standardTable.series[i].seriesSort]) ? this.signalObj[this.standardTable.series[i].seriesSort] : null;
									// if (this.signalObj[this.standardTable.series[i].seriesSort] == undefined) {
									// 	seriesFlag = true;
									// }
								}
							}
						}
						this.standardTable.seriesRow.push(childObj)
					}
					if (seriesFlag) {
						this.$notify({
							title: "警告",
							message: "缺少信号值",
							type: "wraning"
						});
						//return;
					}
					//渲染曲线
					console.log(this.standardTable.seriesRow)
					var arr = [];//一组点位[[x,y],[x1,y1],[x2,y2],[x3,y3]、、、]
					for (var i in this.standardTable.seriesRow[0]) {
						if (i != 'title' && this.standardTable.seriesRow[1][i] != null && this.standardTable.seriesRow[0][i] != null) {
							var childArr = [];//一个点位的坐标[x,y]
							childArr[0] = this.standardTable.seriesRow[0][i];//x的坐标
							childArr[1] = this.standardTable.seriesRow[1][i];//y的坐标
							arr.push(childArr)
						}

					}
					var x = [], y = [];
					for (var j in arr) {
						x.push(Number(arr[j][0]));
						y.push(Number(arr[j][1]));
					}
					this.getCoefficient(x, y, arr)


				}
        if(val == 'fourth'){
           this.getFilePath()
        }
			}
		},
		props: ['addVisible', 'standardSeriesDetail','standarModel','testpanelDetail'],
		components: {

		},
		mounted() {
			this.readAllUnit();
			this.readUser();
		},
		computed: {
			...mapState(['tableHeightA']),
		},
		methods: {
      timeFormatter(row, column, cellValue, index) {
          return this.util.formatterDate({
              cellValue: cellValue
          })
      },
      getFilePath() {
          this.$http({
              method: 'post',
              apiUrl: '/download/getFilePathByIds.htm',
              params: {
                  ids: this.standardSeriesForm.batch
              },
              isJson: false,
          }).then(res => {
              if (res.code == 0) {
                  this.attachmentBeanList = res.data
              }
          })
      },
      // 下载附件
      downloadattachment(row) {
          var url = "/download/fileDownload.htm"
          let token = sessionStorage.getItem('loginAccount')?sessionStorage.getItem('loginAccount'):undefined
          window.open(process.env.baseUrl + url + '?id=' + row.id + "&token=" + token);
      },
			 // 读取单位
            readAllUnit(item) {
                this.allUnit = [];
                this.$http({
                    method: 'post',
                    apiUrl: '/technology/readLabUnitList.htm',
                    params: { ename: item },
                    isJson: true
                }).then(res => {
                    if (res.code == 0) {
                        this.allUnit = res.data;
                    }
                })
            },
            // 读取用户
            readUser(item) {
                this.$http({
                    method: 'post',
                    apiUrl: '/resource/readEmployeeByLab.htm',
                    params: { name: item },
                    isJson: true,
                }).then(res => {
                    if (res.code === 0) {
                        this.userData = res.data;

                    }

                })
            },
			// 渲染标准溶液表头部的单位input框
			renderHeader(h, { column, $index }) {
				var that = this;
				var label = '';
				var mes = "";
				if ($index == '2') {  //根据当前列是第几列显示表头和为输入框绑定值
					label = "标准物质浓度";
					mes = 'unitOne';
				} else if ($index == '3') {
					label = "标准物质用量"
					mes = 'unitTwo';
				} else if ($index == '4') {
					label = "定容体积"
					mes = 'unitThree';
				} else if ($index == '6') {
					label = "配置浓度"
					mes = 'unitFour';
				}
				return h('div', {
					style: {
						height: '63px',
						lineHeight: "27px",
					},
				}, [
						h("span", {//div里面有一个文字提示：下拉框所属内容
							style: {
							},
						}, label),
						h("br", {

						}),
						h('el-select', {//el-input
							on: {	//这是方法
								input: (value) => {
									that.$set(that.unitTitle, mes, value);
								},
							},
							style: {
								width: '110px',


							},
							class: 'el-input--mini unitSolution',
							props: {
								value: that.unitTitle[mes],
								placeholder: '单位',
								filterable: true,
								disabled: this.isDisabled
							},

						}, [this.allUnit.map(item => {
							return h("el-option", {
								props: {
									value: item.id,
									label: item.ename
								}
							})
						})
							])
					])
			},
			// 添加标准溶液
			addStandardSolution() {
				this.standardSolution.push({
					name: '',
					matter: '',
					matterConcen: '',
					matterAmount: '',
					volum: '',
					matrix: '',
					configConcen: '',

				})
			},
			// 添加标准系列
			addStandardSeries() {
				// 如果勾选是否应用，不能添加长度大于1标准系列项目
				if (this.standardSeriesForm.doUse && this.standardSeries.length > 0) {
					this.$message({
						type: 'info',
						message: '已勾选"是否应用",只能添加一个项目'
					});
					return;
				}
				this.$prompt('请输入标准点个数', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					inputPattern: /^[5-9]|10\d*$/,
					inputErrorMessage: '请输入大于5小于10的整数'
				}).then(({ value }) => {
					this.$message({
						type: 'success',
						message: '你的要加入的列数是: ' + value
					});
					var colsData = [];
					var obj = {};
					for (var i = 1; i <= value; i++) {
						obj = { value: "std" + i, label: "std" + i }
						// this.colsData.push(obj)
						colsData.push(obj)
					}
					var unitValue1 = '';
					// var unitUse = true;
					// 添加时如果勾选是否应用，默认单位为mg/l，并且不可用
					if (this.standardSeries.length == 0 && this.standardSeriesForm.doUse) {
						unitValue1 = 'mg/L'
						// unitUse = false;

					}
					this.standardSeries.push({
						seriesItem: '',
						custom: {
							standardSeriesChild: [{
								title: '标准使用液浓度',
								// unit:'单位 : ',
								unitValue: '',
								// disabledUnit: true,
							}, {
								title: '标准物质用量',
								// unit:'单位 : ',
								unitValue: '',
								// disabledUnit: true,
							}, {
								title: '定容量',
								// unit:'单位 : ',
								unitValue: '',
								// disabledUnit: true,
							}, {
								title: '标准系列浓度',
								// unit:'单位 : ',
								unitValue: unitValue1,
								// disabledUnit: unitUse,
							}],
							colsData
						},

					})
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '取消输入'
					});
				});

			},
			// 点击是否应用时调用的函数
			itemSize(val) {
				// 如果勾选并且标准系列长度大于1，不能勾选
				if (val && this.standardSeries.length > 1) {
					this.$message({
						type: 'info',
						message: '标准系列项目大于1条,请删除后再勾选'
					});
					this.standardSeriesForm.doUse = false;
				}
				this.defaultUnit(val);
			},
			// 如果勾选是否应用 默认设置标准系列浓度单位为mg/l 其他列清空
			defaultUnit(val) {
				if (val && this.standardSeries.length == 1) {
					// 清空第四行数据，循环std数据
					for (var j in this.standardSeries[0].custom.colsData) {
						var std = this.standardSeries[0].custom.colsData[j].value
						this.standardSeries[0].custom.standardSeriesChild[3][std] = undefined;
					}
					this.standardSeries[0].custom.standardSeriesChild[3].unitValue = 'mg/L';
					this.standardSeries[0].custom.standardSeriesChild[3].title = '标准系列浓度';
					this.standardSeries[0].custom.standardSeriesChild[3].unit = '单位 : '
					// this.standardSeries[0].custom.standardSeriesChild[3].disabledUnit = false;
				}
				// 不准修改标准系列浓度单位

			},

			// 删除标准溶液
			deleteStandardSolution(index) {
				this.standardSolution.splice(index, 1)
			},
			// 删除标准系列
			deleteStandardSeries(index) {
				this.standardSeries.splice(index, 1)
			},
			// 验证标准系列不为空
			isNotNull(str, msg) {
				if (str == "" || str == undefined) {
					this.$message({
						type: 'info',
						message: msg + "不能为空！"
					})
					this.breakFlag = 0;
				} else {
					this.breakFlag = this.breakFlag * 1;
					return str;
				}
			},
			stringNotEmpty(str) {
				if (str != undefined && str != null && str != '') {
					return true;
				} else {
					return false;
				}
			},
			// /qc/readQcTypes.htm
			readQcTypes(beans) {
				var standardSample = [];
				this.$http({
					method: 'post',
					apiUrl: '/qc/readQcTypes.htm',
					params: {
						genre: "QCB04"
					},
					isJson: false
				}).then(res => {
					if (res.code == 0) {
						for (var j in beans) {
							var obj = {};
							obj.sampleName = "标准系列" + beans[j].seriesSort;
							obj.doStandard = true;
							obj.qcType = res.data[0].code;
							obj.qcTypeName = res.data[0].name;
							obj.sampleCode = '/';
							// obj.taskName = '---';
							standardSample.unshift(obj)
						}
						var list = this.util.repeatData({ old: this.testpanelForm.sampleBeans, new: standardSample, unique: 'sampleName' })
						this.testpanelForm.sampleBeans = this.$parent.sampleSort(list);
						this.closeStandardSeriesShow();

					}
				})
			},
			// 赋值标准系列
			copyStandardSeries(row) {
				var colsData = JSON.parse(JSON.stringify(row.custom.colsData))
				var standardSeriesChild = JSON.parse(JSON.stringify(row.custom.standardSeriesChild))
				this.standardSeries.push({
					seriesItem: '',
					custom: {
						standardSeriesChild,
						colsData
					},

				})
			},
			// 查看历史曲线
			historyLine() {

			},
			closeStandardSeriesShow() {
				this.$refs.standardSeriesForm.resetFields();
				this.$emit('update:addVisible', false)
				this.name = '';
				this.unitTitle = {
					unitOne: '',
					unitTwo: '',
					unitThree: '',
					unitFour: '',
				};
				this.matterType = 1; //默认单标
				this.configWay = 1; // 配置方式默认为人工配置

				this.standardSeriesForm = {
					code: '',
					configDate: null,
					temperature: '',
					humcodeity: '',
					doUse: false,
          mustZone:true,
					configMan: JSON.parse(sessionStorage.getItem('laboratoryAccountInfo')).loginid,
					checker: '',

				};
				this.standardSolution = [];
				this.standardSeries = [];
				this.activeName = 'first';
			},
			// getCoefficient(x1, y1, arr) {
			// 	var that = this;
			// 	var ySignal = null;
			// 	var x = x1;
			// 	var y = y1;
			// 	if (x.length > 0) {
			// 		for (var i in x) {
			// 			if (x[i] == 0) {
			// 				ySignal = y[i];
			// 				break;
			// 			}
			// 		}
			// 		if (ySignal == null) {
			// 			this.$notify({
			// 				title: "警告",
			// 				type: "warning",
			// 				message: "无法查到标准系列浓度为0 的标准系列空白样品,无法计算曲线",

			// 			})
			// 			return;
			// 		} else {
			// 			for (var j in y) {
			// 				y[j] = Number(this.$math.eval(y[j] - ySignal)).toFixed(4);
			// 			}
			// 		}
			// 	}
			// 	if(x.length == 0 || y.length == 0){
			// 		return;
			// 	}



			// 	var data = [];
			// 	this.$http({
			// 		method: 'post',
			// 		apiUrl: '/detection/getCoefficient.htm',
			// 		params: {
			// 			x: x1,
			// 			y: y1
			// 		},
			// 		isJson: true
			// 	}).then(res => {
			// 		this.getCoefficientObj.coefficent = res.data.coefficent.toFixed(4);//相关系数
			// 		this.getCoefficientObj.deviation = res.data.deviation.toFixed(4);//截距
			// 		this.getCoefficientObj.slope = res.data.slope.toFixed(4); //斜率
			// 		//根据截距与斜率计算两个点位
			// 		var newArr = this.getLinePoint(arr,ySignal);

			// 		var fuhao = null
			// 		if (Number(res.data.deviation) >= 0) {
			// 			fuhao = '* x +' + res.data.deviation.toFixed(4);//截距
			// 		} else {
			// 			fuhao = '* x ' + res.data.deviation
			// 		}
			// 		var cron = "y = " + res.data.slope.toFixed(4) + fuhao
			// 		console.log(arr, cron)
			// 		setTimeout(function () {
			// 			that.drawLine(newArr, cron);
			// 		}, 300)
			// 	})
			// },
      getCoefficient(x1, y1, arr) {

            var that = this;
            var x = x1;
            var y = y1;

            var y0 = 0
            if (x.length > 0) {

              if(this.standardSeriesForm.mustZone){
                y0 = y[0]
                for (var j in y) {
                    y[j] = Number(this.$math.eval(y[j] - y0)).toFixed(4);
                }
              }

            }
            if (x.length == 0 || y.length == 0) {
                return;
            }

            var data = [];
            this.$http({
                method: 'post',
                apiUrl: '/detection/getCoefficient.htm',
                params: {
                    x: x1,
                    y: y1
                },
                isJson: true
            }).then(res => {
                console.log(res.data)
                this.getCoefficientObj.coefficent = res.data.coefficent.toFixed(4);
                this.getCoefficientObj.deviation = res.data.deviation.toFixed(4);
                this.getCoefficientObj.slope = res.data.slope.toFixed(4);
                //根据截距与斜率计算两个点位
                var newArr = this.getLinePoint(arr, y0);

                var fuhao = null
                if (Number(res.data.deviation) >= 0) {
                    fuhao = '* x +' + res.data.deviation.toFixed(6); //截距
                } else {
                    fuhao = '* x ' + res.data.deviation.toFixed(6)
                }
                var cron = "y = " + res.data.slope.toFixed(6) + fuhao

                setTimeout(function() {
                    that.drawLine(newArr, cron);
                }, 300)
            })
        },
			getLinePoint(arr,ySignal) {  // //将 每个信号值 减去 浓度为0的信号值
				//根据数组获取两个x坐标轴的点
				// 开始计算图表的第一个点和最后一个点
				// var tempArr = [];
				// var y1 = eval(x[0] * slope + deviation); //第一组点位
				// var pointArr = [];
				// //起点
				// pointArr.push(x[0]);
				// pointArr.push(y1);
				// //坐标点为(0,b)

				// var y2 = eval((x[x.length - 1]) * slope + deviation);//第二组点位
				// var pointArr2 = [];
				// pointArr2.push(x[x.length - 1]);
				// pointArr2.push(y2);
				// tempArr.push(pointArr);
				// tempArr.push(pointArr2);
				// return tempArr;
				// 结束计算图表的第一个点和最后一个点

				for (var i in arr) {
					arr[i][1] = arr[i][1] - ySignal;
					arr[i][1] = Number(this.$math.eval(arr[i][1])).toFixed(4)
				}
				return arr;


			},
			drawLine(arr, cron, tempArr) {//arr是点位数据，cron是表达式
				// console.log(arr, cron, tempArr[0]);

				let seriesMap = this.$echarts.init(document.getElementById('seriesMap'))
				// 绘制图表
				var dataAll = arr; //所有点位

				// 取所有点中x轴最大数据和y轴最大数据,用来控制x轴和y轴长度
				var xMax = null;
				var yMax = null;
				for (var i in arr) {
					xMax = (xMax <Number(arr[i][0])) ? Number(arr[i][0]) : xMax;
					yMax = (yMax < Number(arr[i][1])) ? Number(arr[i][1]) : yMax;
				}

				var markLineOpt = {
					animation: false,
					label: {
						normal: {
							formatter: cron,
							textStyle: {
								align: 'right'
							}
						}
					},
					lineStyle: {
						normal: {
							type: 'solid',
						}
					},
					tooltip: {
						formatter: cron
					},
					data: [
						[{
							coord: arr[0],
							symbol: 'none'
						}, {
							coord: arr[arr.length - 1],
							symbol: 'none'
						}]
					]
				};
				seriesMap.setOption({
					title: {
						text: '曲线图谱',
						x: 'center',
						y: 0,
						textStyle: {
							fontSize: 14
						}
					},
					grid: [
						{ x: 'center', y: 'center', width: '80%', height: '80%' },
					],
					tooltip: {
						formatter: '{a}: ({c})'
					},
					xAxis: [
						{ gridIndex: 0, min: 0, max: xMax,name:'浓度' },
					],
					yAxis: [
						{ gridIndex: 0, min: 0, max: yMax,name:'信号值'},
					],
					series: [
						{
							name: '坐标',
							type: 'scatter',
							xAxisIndex: 0,
							yAxisIndex: 0,
							data: dataAll,
							markLine: markLineOpt,
							itemStyle: {
								color: '#409EFF'
							}
						}
					]
				});
			}

		}

	}

</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
	.addSampleForm .el-dialog {
		height: 85%;
		margin-top: 7vh !important;
	}

	.addSampleForm .el-dialog .el-form-item {
		margin-bottom: 20px;
	}

	.addSampleForm .el-dialog .el-dialog__body {
		height: calc(100% - 85px);
		padding: 10px;
	}
	.dataEntrySeries.addSampleForm .el-dialog .el-dialog__body {
		height: calc(100% - 45px);
	}
	/*标准系列标题样式*/

	.standardTitle {
		height: 42px;
		line-height: 20px;
		text-align: center;
	}

	.standardTitle .el-input {
		width: 24%;
		margin-right: 8px;
	}

	.standardTitle .el-input .el-input__inner,
	.borderBottom .el-input__inner {
		border: none;
		border-bottom: 1px solid #dcdfe6;
		border-radius: 0;
	}

	.standardseries.addSampleForm .el-dialog .el-dialog__body .form {
		height: 90px;
	}

	.standardseries.addSampleForm .el-dialog .el-dialog__body .form .el-form-item {
		width: 24%;
		display: inline-block;
		margin-bottom: 5px;
	}

	.standardseries .standardTable {
		/*height: calc((100% - 95px - 42px)/2);*/
		height: calc(100% - 90px - 42px);
		padding: 0 10px;
	}

	.standardTable .el-tabs.el-tabs--top {
		height: 100%;
	}

	.standardTable .el-tabs__content {
		height: calc(100% - 55px)
	}

	.standardTable .el-tabs__content .el-tab-pane {
		height: 100%
	}

	.standardseries .standardTable .el-table {
		height: calc(100% - 30px)
	}

	.standardseries .checkbox {
		height: 30px;
		padding: 0 20px;
		line-height: 36px;
	}

	.standardTable .solution .el-table__fixed-body-wrapper,
	.standardTable .solution .el-table__body-wrapper {
		height: calc(100% - 82px);
		overflow: auto;
	}

	.standardTable .seriesTable>.el-table__body-wrapper>.el-table__body>tbody>tr>td:nth-of-type(3),
	.standardTable .seriesTable>.el-table__body-wrapper>.el-table__body>tbody>tr>td:nth-of-type(3)>.cell {
		padding: 0;
	}

	.seriesChildTable .el-table__header-wrapper .has-gutter th,
	.seriesChildTable .el-table__fixed .el-table__fixed-header-wrapper th {
		background: none !important;
	}

	.seriesChildTable tr td:nth-of-type(1),
	.seriesChildTable tr th:nth-of-type(1) {
		border-right: none;
	}

	.seriesChildTable tr th:nth-of-type(1) .cell,
	.seriesChildTable tr td:nth-of-type(1) .cell {
		text-align: right;
	}

	.unitSolution {
		padding-right: 0px !important;
		padding-left: 0px !important;
	}

	.unitSolution .el-input__suffix {
		right: 10px;
	}

	.unitSeries .el-input__suffix {
		right: 0px;
	}

	.unitSeries .el-input__inner,
	.unitSolution .el-input__inner {
		padding-right: 22px;
		padding-left: 10px;
	}

	.seriesChildTable tr th:nth-of-type(1) .cell,
	.seriesChildTable tr td:nth-of-type(1) .cell {
		text-align: right;

		padding: 0;
	}

	.seriesChildTable .controlsPosition {
		width: 100%;
	}

	.controlsPosition.el-input-number .el-input__inner {
		text-align: left;
	}

	.seriesChildTable .controlsPosition.el-input-number .el-input__inner {
		padding-left: 5px;
		padding-right: 5px;
		text-align: center;
	}
	.solution .el-table__fixed-body-wrapper {
		top: 83px !important;
	}
</style>
